package com.tongji.housediy.view.titlewindows
{
	import com.tongji.housediy.events.commonEvent.PopupBtnAdminEvent;
	import com.tongji.housediy.events.goodsEvent.FilterGoodsEvent;
	import com.tongji.housediy.model.GoodsModel;
	import com.tongji.housediy.model.ListTypeModel;
	import com.tongji.housediy.vo.Goods;
	
	import mx.binding.utils.BindingUtils;
	import mx.events.ListEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	import spark.events.IndexChangeEvent;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class MaterialListMediator extends Mediator
	{
		[Inject]
		public var view:MaterialList;
		
		[Inject]
		public var xmlModel:ListTypeModel;
		
		[Inject]
		public var model:GoodsModel;
		
		override public function onRegister():void
		{
			switch (model.titleName)
			{
				case "地面色彩":
					dispatch(new FilterGoodsEvent(FilterGoodsEvent.FILTER_GOODS, "floorList1", []));
					BindingUtils.bindProperty(view, "dataProvider", model, "floorArrayCollection");
					break;
				case "墙面色彩":
					dispatch(new FilterGoodsEvent(FilterGoodsEvent.FILTER_GOODS, "wallTypeList1", xmlModel.wallArray));
					BindingUtils.bindProperty(view, "dataProvider", model, "wallArrayCollection");
					break;
				case "踢脚线色彩":
					dispatch(new FilterGoodsEvent(FilterGoodsEvent.FILTER_GOODS, "wallTypeList1", xmlModel.skirtingArray));
					BindingUtils.bindProperty(view, "dataProvider", model, "wallArrayCollection");
					break;
			}
			
			view.addEventListener(IndexChangeEvent.CHANGE, indexChangeHandler);
		}
		
		private function indexChangeHandler(event:IndexChangeEvent):void
		{
			model.arrangeSizes(view.selectedItem as Goods);
			dispatch(new PopupBtnAdminEvent(PopupBtnAdminEvent.CLOSE_POPUP_BUTTON, view.selectedItem as Goods));
		}
	}
}